<template>
	<div>
		<main-head><i id="head" class="iconfont icondingdandingdanmingxishouzhimingxi"></i>商品订单详情
			<span slot="after" @click="$router.go(-1)" type="primary" size="medium" icon="el-icon-plus">
				<span style="font-weight: 700;color: #444444;cursor: pointer;">返回上一页</span>
				<i class="iconfont iconfanhui" style="color: #0482d1;margin-left: 10px;cursor: pointer;"></i>
			</span>
		</main-head>

		<div v-if="show">
			<el-empty description="订单可能已经被删除了哦~"></el-empty>
		</div>
		<div v-else>
			<el-card style="margin-top: 20px" shadow="hover">
				<div slot="header" class="clearfix">
				    <span>用户购买的商品</span>				
				  </div>
				<el-descriptions :column="3" title="商品信息(快照)" v-for="(item,index) in JSON.parse(form.goodsOrder.snapshot)">
					<el-descriptions-item label="商品id">
						{{item.id}}
					</el-descriptions-item>
					<el-descriptions-item label="商家id" v-if="form.goodsOrder.type==2">
						{{item.merchantId}}
					</el-descriptions-item>
					<el-descriptions-item label="商品名称">
						{{item.title}}
					</el-descriptions-item>
					<el-descriptions-item label="商品简介">
						{{item.overview}}
					</el-descriptions-item>
					<el-descriptions-item label="商品单价">
						{{item.price}}
					</el-descriptions-item>
					<el-descriptions-item label="数量">
						x{{item.count}}
					</el-descriptions-item>
					<el-descriptions-item label="商品主图">
						<el-image :src="item.avatar" style="width: 20%"
							:preview-src-list="item.avatar.split(',')">
						</el-image>
					</el-descriptions-item>
					<el-divider></el-divider>
				</el-descriptions>
			</el-card>
			<el-card style="margin-top: 20px;" shadow="hover">
				<div slot="header" class="clearfix">
				    <span>用户信息</span>			
						<el-button type="success"  v-if="form.goodsOrder.status==1&&form.goodsOrder.type==1" @click="applyDialog=true" style="float: right; padding: 2px 10">
							<i class="iconfont iconfahuo"></i>发货
						</el-button>
				  </div>				
				<el-descriptions :column="2" title="用户信息" style="margin-top: 10px;">
					<el-descriptions-item label="微信头像" content-class-name="my-content" label-class-name="label">
						<el-image :src="form.avatar" style="width: 80%;border-radius: 50%;"
							:preview-src-list="form.avatar.split(',')">
						</el-image>
					</el-descriptions-item>
					<el-descriptions-item label="微信昵称" content-class-name="my-content" label-class-name="label">
						{{form.nick}}
					</el-descriptions-item>
				</el-descriptions>
				<el-divider></el-divider>
				<el-descriptions :column="3" title="订单信息">
					<el-descriptions-item label="订单编号" content-class-name="my-content" label-class-name="label">
						{{form.goodsOrder.orderNum}}
					</el-descriptions-item>
					<el-descriptions-item label="商品类型" content-class-name="my-content" label-class-name="label">
						{{form.goodsOrder.type==1?"平台商品":"商家商品 "}}
					</el-descriptions-item>
					<el-descriptions-item label="订单状态" content-class-name="my-content" label-class-name="label">
						<span v-html="getStatus(form.goodsOrder.status)"></span>
					</el-descriptions-item>
					<el-descriptions-item label="数量" content-class-name="my-content" label-class-name="label">
						{{form.goodsOrder.count}}
					</el-descriptions-item>
					<el-descriptions-item label="总价" content-class-name="my-content" label-class-name="label">
						{{form.goodsOrder.totalPrice}}
					</el-descriptions-item>
					<el-descriptions-item label="应付价格" content-class-name="my-content" label-class-name="label">
						{{form.goodsOrder.realPrice}}
					</el-descriptions-item>
					<el-descriptions-item label="收货人名称" content-class-name="my-content" label-class-name="label">
						{{form.address.name}}
					</el-descriptions-item>
					<el-descriptions-item label="收货人电话" content-class-name="my-content" label-class-name="label">
						{{form.address.phone}}
					</el-descriptions-item>
					<el-descriptions-item label="收货地址" content-class-name="my-content" label-class-name="label">
						{{form.address.province+" "+form.address.city+" "+form.address.area+" "+form.address.address}}
					</el-descriptions-item>
					<el-descriptions-item label="备注" content-class-name="my-content" label-class-name="label">
						{{form.address.remark!=null?form.address.remark:"无"}}
					</el-descriptions-item>
				</el-descriptions>
			</el-card>

			<!-- 发货dialog -->
			<el-dialog title="提交申请" :visible.sync="applyDialog" width="30%" :close-on-click-modal="false" center>
				<el-form :model="sendForm" :label-width="labelWidth" :rules="rule" ref="form">

					<el-radio v-model="sendForm.type" label="1">快递</el-radio>
					<el-radio v-model="sendForm.type" label="2">自取或其他</el-radio>
					<!-- </el-form-item>	 -->

					<el-form-item label="快递单号：" prop="expressNumber" v-if="sendForm.type==1">
						<el-input v-model="sendForm.expressNumber">
						</el-input>
					</el-form-item>
				</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button type="success" @click="apply()">发货</el-button>
					<el-button type="warning" @click="applyDialog=false">关闭</el-button>
				</div>
			</el-dialog>
		</div>
	</div>
</template>

<script>
	import editor from '@/components/utils/CustomWangEditor';

	export default {
		components: {
			editor
		},
		data() {
			return {
				show: false,
				id: "",
				form: {},
				sendForm: {},
				applyDialog: false
			};
		},

		mounted() {
			let url = this.$route.fullPath;
			if (url.indexOf("?") != -1) {
				let id = url.substr(url.indexOf("=") + 1);
				this.sendForm.id = id
				this.getInfo(id);
			} else {
				this.show = true
			}
		},

		methods: {
			getStatus(status) {
				switch (status) {
					case 0:
						return "<font style='color: #6b6a70'>待付款</font>"
					case 1:
						return "<font style='color: #409eff'>待发货</font>"
					case 2:
						return "<font style='color: #e1b919'>待收货</font>"
					case 3:
						return "<font style='color: #3daa3d'>待评价</font>"
					case 4:
						return "<font style='color: #67c23a'>已完成</font>"
					case -1:
						return "<font style='color: red'>已取消</font>"
				}
			},
			getInfo(id) {
				this.$request.post({
					url: "admin/adGoodsOrder/detail",
					params: {
						id
					},
					success: (result) => {
						this.form = result
					},
					error: () => {
						this.show = true
					},
				});
			},
			apply() {
				this.$request.post({
					url: "admin/adGoodsOrder/delivery",
					params: this.sendForm,
					success: (result) => {
						this.$message.success("发货成功！");
						this.applyDialog = false;
						this.getInfo(this.sendForm.id)
					},
				});
			}
		},
	};
</script>

<style>
	#head {
		color: #0949D1;
		font-size: 30px;
	}

	.label {
		margin-top: 10px;
		color: #0482d1;
	}

	.my-content {
		margin-top: 10px;
		/* background-color: #f4f4f5; */
		border-radius: 10%
			/* color: #0949D1;		 */
	}

	el-card {}
</style>
